//
//  ViewController3.m
//  PASystem
//
//  Created by michael on 16/7/19.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "ViewController3.h"

@interface ViewController3 ()

@end

@implementation ViewController3

- (void)viewDidLoad {
    [super viewDidLoad];
 UIColor *myColor = [UIColor colorWithWhite:0.8 alpha:0.3];

    self.view.backgroundColor = [UIColor whiteColor];
_view0 = [[UIView alloc]initWithFrame:self.view.frame];
_view0.backgroundColor = myColor;
[self.view addSubview:_view0];
    self.title = @"个人中心";
    
   }
- (void)viewWillAppear:(BOOL)animated{

 [self request];


}
- (void)request{
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
 NSString *json =[NSString stringWithFormat: @"{'action':getPersonal,'service': UserService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@}'}",userId,pwdId,userHumber];
     NSArray * array = @[@{@"arg0":json}];
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {

       
     NSDictionary *dic = JSON[@"reason"];
        
    NSDictionary *dict = dic[@"attrs"];
    
    _dic = dict;
    
NSLog(@"%@",_dic);
        [self initview];
       [_view3 reloadData];
    } failure:^(NSError *error) {
        
    }];
 
}

- (void)initview{

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, (KScreenHeight-64-26)/2)];
view.backgroundColor = [UIColor blueColor];
UIImageView*image = [[UIImageView alloc]initWithFrame:CGRectMake((KScreenWidth-100)/2, (view.height-100)/2-40, 100, 100)];
image.image = [UIImage imageNamed:@"头像"];
//image.backgroundColor = [UIColor whiteColor];
[view addSubview:image];

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake((KScreenWidth-80)/2,image.bottom+10, 80, 30)];
label.text = _dic[@"NAME"];
     label.font = [UIFont systemFontOfSize:15];
label.textAlignment = NSTextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
[view addSubview:label];

UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake((KScreenWidth-80)/2,label.bottom+10, 80, 30)];
label1.text = _dic[@"JOBE"];
     label1.font = [UIFont systemFontOfSize:14];
label1.textAlignment = NSTextAlignmentCenter;
label1.backgroundColor = [UIColor clearColor];
label1.textColor = [UIColor whiteColor];
[view addSubview:label1];


_view3 = [[UITableView alloc]initWithFrame:CGRectMake(5, view.bottom+10, KScreenWidth-10, 120) style:UITableViewStylePlain];
_view3.dataSource = self;
_view3.delegate = self;
self.view3.bounces = NO;
_view3.backgroundColor = [UIColor yellowColor];

_view3.separatorStyle = NO;

[_view0 addSubview:view];
[_view0 addSubview:_view3];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

if (indexPath.row ==0) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(10,10,cell. contentView.height-20, cell. contentView.height-20)];
    image.image = [UIImage imageNamed:@"归属公司"];
[cell.contentView addSubview:image];

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(image.right +10, 0, 100, cell.contentView.height)];
      cell.selectionStyle = UITableViewCellSelectionStyleNone;
    label.text = @"归属公司:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth  -130-image.width, label.height)];
    label2.text = [NSString stringWithFormat:@"%@",_dic[@"COMPANY"]];
      label2.textAlignment = NSTextAlignmentRight;

     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}if (indexPath.row ==1){
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
       UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(10,10,cell. contentView.height-20, cell. contentView.height-20)];
    image.image = [UIImage imageNamed:@"归属部门"];
[cell.contentView addSubview:image];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(image.right +10, 0, 100, cell.contentView.height)];
    label.text = @"归属部门:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth  -130-image.width, label.height)];
    label2.text = [NSString stringWithFormat:@"%@",_dic[@"OFFICE"]];
      label2.textAlignment = NSTextAlignmentRight;

     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}else{
 UITableViewCell* cell = [[UITableViewCell alloc]init];
  UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(10,10,cell. contentView.height-20, cell. contentView.height-20)];
    image.image = [UIImage imageNamed:@"我的通讯录"];
[cell.contentView addSubview:image];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头  

     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(image.right +10, 0, 100, cell.contentView.height)];
    label.text = @"我的通讯录";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
//  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth  -120, label.height)];
//    label2.text = [NSString stringWithFormat:@"%@",_dic[@"OFFICE"]];
//      label2.textAlignment = NSTextAlignmentRight;
//
//     label2.font = [UIFont systemFontOfSize:12];
//    [cell.contentView addSubview:label2];
    return cell;


}


}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row ==2) {
    txlTableViewController *vc = [[txlTableViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}


}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
